package io.github.shenbinglife.springboot2.layui.admin.dao;

import io.github.shenbinglife.springboot2.layui.admin.entity.Dict;
import io.github.shenbinglife.springboot2.layui.common.jpa.IBaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DictDao extends IBaseRepository<Dict, Long> {
    List<Dict> findByType(String type);

    @Query(value = "select d from Dict d where :keyword is null" +
            " or d.code like CONCAT('%',:keyword,'%') " +
            " or d.codeName like CONCAT('%',:keyword,'%')" +
            " or d.type like CONCAT('%',:keyword,'%')" +
            " or d.typeName like CONCAT('%',:keyword,'%')")
    Page<Dict> findByKeywordWithPagination(@Param("keyword") String keyword, Pageable pageable);
}
